package com.company.exp2.factory;

import com.company.exp2.event.Event;
import com.company.exp2.event.impl.*;
import com.company.exp2.station.Station;
import com.company.exp2.typeEnum.EventType;

/**
 * @author dyy
 *
 *  Event 的工厂类
 *  需要给出工厂类创建的默认 Event 类型
 *
 *  createInstance:
 *      根据提供的执行器类型创建一个 EventExecutor 实例并返回
 *
 *   createDefaultInstance:
 *      创建一个默认的执行器并返回
 */
public class EventFactory {

    public static Event createInstance(EventType type, long occurTimestamp, Station associatedStation) {
        switch (type) {
            case CREATE_FRAME:
                return new CreateFrameEvent(occurTimestamp, associatedStation);
            case FRAME_TIMEOUT:
                return new FrameTransmissionTimeoutEvent(occurTimestamp, associatedStation);
            case CHANNEL_TRANSMITTABLE:
                return new ChannelTransmittableEvent(occurTimestamp, associatedStation);
            case CHANNEL_FORBIDDEN:
                return new ChannelForbiddenEvent(occurTimestamp, associatedStation);
            case FRAME_START_TRANSMIT:
                return new FrameStartTransmittingEvent(occurTimestamp, associatedStation);
            case FRAME_END_TRANSMIT:
                return new FrameTransmissionFinishedEvent(occurTimestamp, associatedStation);
            default:
                return new StartModelEvent(occurTimestamp, associatedStation);
        }
    }

}
